package com.heima.comment.controller.v1;

import com.heima.comment.service.CommentRepayService;
import com.heima.comment.service.CommentService;
import com.heima.model.comment.dtos.*;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Program: day57-leadnews
 * @Description: APP端评论系统
 * @Data: 2022/8/5 23:14
 **/
@Api(value = "app端评论系统api",tags = "app端评论系统api")
@RestController
@RequestMapping("/api/v1")
public class CommentController {

    @Autowired
    CommentService commentService;

    @Autowired
    CommentRepayService commentRepayService;

    @ApiOperation("发表评论")
    @PostMapping("/comment/save")
    public ResponseResult save(@RequestBody @Validated CommentSaveDTO dto){
        return commentService.saveComment(dto);
    }

    @ApiOperation("保存评论点赞")
    @PostMapping("/comment/like")
    public ResponseResult like(@RequestBody @Validated CommentLikeDTO dto){
        return commentService.likeComment(dto);
    }

    @ApiOperation("根据文章id查询文章列表")
    @PostMapping("/comment/load")
    public ResponseResult load(@RequestBody @Validated CommentDTO dto){
        return commentService.findByArticleId(dto);
    }

    @ApiOperation("加载评论回复列表")
    @PostMapping("/comment_repay/load")
    public ResponseResult repayLoad(@RequestBody @Validated CommentRepayDTO dto){
        return commentRepayService.loadCommentRepay(dto);
    }

    @ApiOperation("保存评论回复")
    @PostMapping("/comment_repay/save")
    public ResponseResult repaySave(@RequestBody @Validated CommentRepaySaveDTO dto){
        return commentRepayService.saveCommentRepay(dto);
    }

    @ApiOperation("点赞回复的评论")
    @PostMapping("/comment_repay/like")
    public ResponseResult repayLike(@RequestBody @Validated CommentRepayLikeDTO dto){
        return commentRepayService.saveCommentRepayLike(dto);
    }
}
